package com.zmn.plat.services.impl.plat.contract.model;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.plat.model.entity.plat.contract.model.PlatContractModel;
import com.zmn.plat.model.entity.plat.contract.model.PlatContractModelQuery;
import com.zmn.plat.persistence.interfaces.plat.contract.model.PlatContractModelDao;
import com.zmn.plat.services.interfaces.plat.contract.model.PlatContractModelService;

@Service
public class PlatContractModelServiceImpl implements PlatContractModelService {

    @Resource
    PlatContractModelDao platContractModelDao;

    @Override
    public PlatContractModel findByKey(Integer id) {
        return platContractModelDao.findByKey(id);
    }

    @Override
    public Integer findByPlat(Integer plat) {
        PlatContractModelQuery platContractModelQuery = new PlatContractModelQuery();
        platContractModelQuery.setPlat(plat);
        List<PlatContractModel> platContractModels = platContractModelDao.listByQuery(platContractModelQuery);
        if (CollectionUtil.isNotNullOrEmpty(platContractModels)) {
            Integer contractModel = platContractModels.get(0).getContractModel();
            return contractModel;
        }

        return null;
    }

    @Override
    public List<PlatContractModel> listPageByQuery(PlatContractModelQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return platContractModelDao.listPageByQuery(query);
    }

    @Override
    public List<PlatContractModel> listByQuery(PlatContractModelQuery query) {
        return platContractModelDao.listByQuery(query);
    }

    @Override
    public List<PlatContractModel> listAll() {
        return platContractModelDao.listAll();
    }

    @Override
    public Integer countByQuery(PlatContractModelQuery query) {
        return platContractModelDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(PlatContractModel platContractModel) {
        return platContractModelDao.updateByKey(platContractModel);
    }

    @Override
    public Integer insert(PlatContractModel platContractModel) {
        return platContractModelDao.insert(platContractModel);
    }

    @Override
    public Integer insertBatch(List<PlatContractModel> platContractModelList) {
        return platContractModelDao.insertBatch(platContractModelList);
    }

    @Override
    public Integer deleteByKey(Integer id) {
        return platContractModelDao.deleteByKey(id);
    }

    @Override
    public Integer deleteAllData() {
        return platContractModelDao.deleteAllData();
    }
}